import { asyncRoutes, routes } from '@/router'
import Cookies from 'js-cookie'
export default{
    state: {
        isCollapse:false,
        tabList:[],
        menu:[],
    },
    mutations: {
        collapseMenu(state){
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state,val){
            if(val.name !== 'home'){
                const index = state.tabList.findIndex(item => item.path === val.path)
                if(index === -1){
                    state.tabList.push(val)
                }
            }
        },
        closeTag(state,item){
            const index = state.tabList.findIndex(val => val.path === item.path)
            state.tabList.splice(index,1)
        },

        generateRoutes(state) {
            var accessedRoutes = []
            routes.forEach((item, index) => {
                if (item.name.includes('Main')) {
                    state.menu = routes[index].children.concat(accessedRoutes)
                    if(Cookies.get('menu') == undefined){
                        Cookies.set('menu',JSON.stringify(state.menu))
                    }
                }
            })
        },
        addMenu(state,router){
            if(!Cookies.get('menu'))
                return
            const menu = JSON.parse(Cookies.get('menu'))
            state.menu = menu
        }
    }
}